package com.tledu.ssm01.controller;

import com.tledu.ssm01.model.User;
import com.tledu.ssm01.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Antg
 * @date 2021/8/12  20:38
 */
@Controller
@AllArgsConstructor
public class LoginController {
    private final UserService userService;

    @GetMapping("/login")
    public String goLoginPage() {
        return "login";
    }

    @PostMapping("/login")
    public String login(String username, String password, HttpServletRequest req) {
        User user = userService.login(username, password);
        req.getSession().setAttribute("userInfo",user);
        return "redirect:/user/list";
    }
}
